<template>
  <app-dialog v-model="show" width="1000px" title="查看设置" @open="handleOpen">
    <el-table class="boardsettingtable" :data="pageData" height="53vh" v-loading="loading">
      <el-table-column label="平台" show-overflow-tooltip>
        <template #default="{ row }">
          {{ platformObj[row.bc_type]?.name || row.bc_type }}
        </template>
      </el-table-column>
      <el-table-column label="盘口" show-overflow-tooltip>
        <template #default="{ row }">
          {{ row.pk_odds_key_ch }}
        </template>
      </el-table-column>
      <el-table-column label="赔率" show-overflow-tooltip>
        <template #default="{ row }">
          <div>{{ row.min_odd + '~ ' + row.max_odd }}</div>
        </template>
      </el-table-column>
      <el-table-column label="下单金额" show-overflow-tooltip>
        <template #default="{ row }">
          <div>{{ getreservationstakerow(row) }}</div>
        </template>
      </el-table-column>
      <el-table-column label="赛前进场时间" show-overflow-tooltip>
        <template #default="{ row }">
          <div>{{ row.before_timer_min + '’~ ' + row.before_timer_max + '’' }}</div>
        </template>
      </el-table-column>
      <el-table-column label="赛中进场时间" show-overflow-tooltip>
        <template #default="{ row }">
          <div>{{ row.ing_timer_min + '’~ ' + row.ing_timer_max + '’' }}</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="80" show-overflow-tooltip>
        <template #default="{ row }">
          <div style="color: #47acff" @click.stop="clickcancel(row)">取消</div>
        </template>
      </el-table-column>
    </el-table>
    <template #footer>
      <el-button @click="show = false">取消</el-button>
      <el-button type="primary" @click="show = false">确定</el-button>
    </template>
  </app-dialog>
</template>

<script setup>
import { http } from '@/utils/http'
import { ElMessage, ElMessageBox } from 'element-plus'

const show = defineModel({ type: Boolean })
const emits = defineEmits(['change'])
const props = defineProps({
  task: Object,
})

const { platformObj } = inject('/home')

const pageData = ref([])
const loading = ref(false)
const orderdata = ref([])

// const { pageData, pageActions, dialog } = usePage(
//   () => {
//     const query = {
//       task_type: props.task.task_type,
//       task_code: props.task.task_code,
//       ...pageData.query,
//     }

//     return http.get('/ordertask/order_gun_data', {
//       params: query,
//     })
//   },
//   {
//     query: {},
//   }
// )

const handleOpen = () => {
  loading.value = true
  let params = {
    task_type: props.task.task_type,
    task_code: props.task.task_code,
    page: 1,
    page_size: 999
  }
  http({
    method: 'get',
    url: '/order/get_order_log',
    params: params,
  }).then(res => {
    loading.value = false
    pageData.value = res.data.list
    orderdata.value = res.data
  })
}

const getreservationstakerow = row => {
  if (row.reservation_stake_type == 'max') {
    return '最大限额'
  } else if (row.reservation_stake_type == 'min') {
    return '最小限额'
  } else if (row.reservation_stake_type == 'custom') {
    return row.reservation_stake
  }
}

// 取消
const clickcancel = row => {
  ElMessageBox.confirm('是否取消枪口?', '提示', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning',
  })
    .then(() => {
      let data = {
        task_code: orderdata.value[0].task_code,
        bc_type: row.bc_type,
        pk_odds_key: row.pk_odds_key
      }
      const onSuccess = () => {
        ElMessage.success('取消成功')
        pageActions.refresh(true)
      }
      http({
        method: 'post',
        url: `/ordertask/delete_reservation_order`,
        data: data
      }).then((res) => {
        console.log(res);
        if (res.code == 200) {
          ElMessage.success('取消成功')
          show.value = false
        } else {
          ElMessage.error(res.msg)
        }
        
      })
    })
    .catch(() => {})
}
</script>

<style lang="scss" scoped>
.boardsettingtable {
  border-radius: 8px;
  border: solid 1px #ebebeb;
}
</style>

<style>
.boardsettingtable tbody {
  color: #252a30;
  font-size: 14px;
}
.boardsettingtable .el-table__cell {
  padding: 12px 0;
}
.boardsettingtable .el-table__empty-block {
  width: 98% !important;
}
</style>